<template>
  <div
    :class="['PublicInfoBlock', settings.process_quick ? '' : 'more-height']"
  >
    <div class="high-title">
      <div class="title">
        <span
          :class="activeName === menuName[1]?.id ? 'active' : ''"
          @click="activeName = menuName[1]?.id"
          style="margin-left: 0"
          >{{ menuName[1]?.menu_name[locale] }}</span
        >
        <span
          :class="activeName === menuName[2]?.id ? 'active' : ''"
          @click="activeName = menuName[2]?.id"
          >{{ menuName[2]?.menu_name[locale] }}</span
        >
      </div>
      <div
        class="see-more"
        @click="
          $router.push({
            path: '/proportal/new',
            query: {
              from:
                activeName === menuName[1]?.id
                  ? 'NoticesManage'
                  : 'RulesManage',
            },
          })
        "
      >
        {{ $t("查看全部", "index.viewAll") }}
        <i class="el-icon-arrow-right"></i>
      </div>
    </div>
    <div v-show="activeName === menuName[1]?.id">
      <div
        class="it"
        v-for="item in sliceAfter(notices)"
        :key="item.id"
        @click="$emit('jumpDetails', item)"
      >
        <div class="base-info">
          <span>{{ item.title }}</span>
          <img
            v-if="item.is_top && locale === 'zh'"
            src="@/assets/images/top_zh.svg"
            alt=""
          />
          <img
            v-if="item.is_top && locale === 'en'"
            src="@/assets/images/top_en.svg"
            alt=""
          />
        </div>
        <div class="time">
          {{ item.create_time_analysis }}
        </div>
      </div>
    </div>
    <div v-show="activeName === menuName[2]?.id">
      <div
        class="it"
        v-for="item in sliceAfter(regulation)"
        :key="item.id"
        @click="$emit('jumpDetails', item)"
      >
        <div class="base-info">
          <span>{{ item.title }}</span>
          <img
            v-if="item.is_top && locale === 'zh'"
            src="@/assets/images/top_zh.svg"
            alt=""
          />
          <img
            v-if="item.is_top && locale === 'en'"
            src="@/assets/images/top_en.svg"
            alt=""
          />
        </div>
        <div class="time">
          {{ item.create_time_analysis }}
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { getActiveNotices, getActiveRegulation } from "@/http/api";
import tools from "@/utils/tools";
export default {
  name: "PublicInfoBlock",
  props: ["menuName", "settings"],
  emits: ["jumpDetails"],
  data() {
    return {
      activeName: "NoticesManage",
      notices: [],
      regulation: [],
      locale: "zh",
    };
  },
  async mounted() {
    this.locale = JSON.parse(localStorage.getItem("locale"));
    let res = await getActiveNotices();
    if (res.code === 20041) {
      this.notices = tools.changeTime(res.data);
    }
    res = await getActiveRegulation();
    if (res.code === 20041) {
      this.regulation = tools.changeTime(res.data);
    }
  },
  methods: {
    sliceAfter(list) {
      if (this.settings.process_quick) {
        return list.slice(0, 3);
      } else {
        return list.slice(0, 5);
      }
    },
  },
};
</script>
<style lang="less" scoped>
.PublicInfoBlock {
  width: 100%;
  height: 236px;
  background-color: #fff;
  position: relative;
  padding: 24px;
  border-radius: 8px;
  &.more-height {
    height: 338px;
  }
  .high-title {
    // display: flex;
    // justify-content: space-between;
    align-items: center;
  }
  .it {
    width: 100%;
    height: 54px;
    line-height: 54px;
    position: relative;
    font-size: 14px;
    color: rgb(31, 35, 41);
    display: flex;
    justify-content: space-between;
    .time {
      color: rgb(100, 106, 115);
    }
  }
  .it:hover {
    cursor: pointer;
    color: rgb(76, 120, 252);
    .time {
      color: rgb(76, 120, 252);
    }
  }
}
</style>
